﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _04_TheBiggestNumberSmallerThenGiven
{
    class Program
    {
        static void Main(string[] args)
        {
            //int k = int.Parse(Console.ReadLine());
            int[] theSeachedArray = { 1, 19, 2, 3, 123131231, -1, 2, 3, 3, 3, 3, 0, 22, 10, 11, 12, 13, 14, 0, 0, 0, 21313 };

            Array.Sort(theSeachedArray);
            var result = ~(Array.BinarySearch(theSeachedArray, -22) + 1);


            // Returns:
            //     The index of the specified value in the specified array, if value is found.
            //     If value is not found and value is less than one or more elements in array,
            //     a negative number which is the bitwise complement of the index of the first
            //     element that is larger than value. If value is not found and value is greater
            //     than any of the elements in array, a negative number which is the bitwise
            //     complement of (the index of the last element plus 1).


            //var result = Array.BinarySearch(theSeachedArray, 22);
            Console.WriteLine(theSeachedArray[result]);
            Console.WriteLine(  );


            foreach (var item in theSeachedArray)
            {
                Console.WriteLine(item);
            }
        }
    }
}
